package servlet;

import impl.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/PythonFileServlet")
public class PythonFileServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sourceName = request.getParameter("sourceName");
        String sourceText = request.getParameter("sourceText");
        String inputText = request.getParameter("inputText");
        long time = System.currentTimeMillis();
        SaveFilePy py = new SaveFilePy(sourceName + time, sourceText,inputText);
        ComRunPy cr = new ComRunPy(sourceName + time);
        String result = cr.comRun();
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(result);
        response.getWriter().close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
